package com.stars.easyms.alarm.client.sms;

import com.stars.easyms.alarm.message.EasyMsAlarmMessage;
import com.stars.easyms.alarm.client.EasyMsAlarmClient;
import com.stars.easyms.alarm.constant.EasyMsAlarmConstant;
import com.stars.easyms.alarm.properties.EasyMsAlarmProperties;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;

/**
 * <p>className: EasyMsSmsAlarmClient</p>
 * <p>description: 短信告警客户端</p>
 *
 * @author caotieshuan
 * @version 1.5.0
 * @date 2019-12-18 16:21
 */
@Slf4j
public final class EasyMsSmsAlarmClient implements EasyMsAlarmClient {

    private EasyMsAlarmProperties.Sms smsAlarmProperties;

    public EasyMsSmsAlarmClient(EasyMsAlarmProperties easyMsAlarmProperties) {
        this.smsAlarmProperties = easyMsAlarmProperties.getSms();
    }

    @Override
    public void sendAlarmMessage(EasyMsAlarmMessage easyMsAlarmMessage) {
        log.info("Sms sendMsg success");
        // todo: 待补充
    }

    @Override
    public String getClientType() {
        return EasyMsAlarmConstant.SMS;
    }

    @Override
    public boolean initAndReturnIsValid() {
        if (smsAlarmProperties.isEnabled()) {
            if (StringUtils.isNotBlank(smsAlarmProperties.getPostUrl())
                    && StringUtils.isNotBlank(smsAlarmProperties.getKey())
                    && StringUtils.isNotBlank(smsAlarmProperties.getToUser())) {
                return true;
            }
            log.error("Easy-ms {} alarm client is enabled, but the config is not valid!", getClientType());
        }
        return false;
    }
}